<?php require_once 'library/Obective.php'; ?>
<?php
$Objective = new Objective();
$Objective->checkUser();
$Objective->isAdmin();
$questions = $Objective->getQuestions();
$groups = $Objective->getRecommendationGroups();
$saved = null;
if (isset($_POST['save'])) {
    unset($_POST['save']);
    unset($_POST['row_sel']);
    if (array_key_exists('data_table_length', $_POST)) {
        unset($_POST['data_table_length']);
    }

    $saved = $Objective->save($_POST);
}

if (isset($_GET['isAjax'])) {
    $Objective->getData($_POST);
    return;
} elseif (isset($_GET['isAjaxUpdate'])) {
    $update = $Objective->update($_POST);
    echo json_encode($update);
    return;
} elseif (isset($_GET['isAjaxDelete'])) {
    $deleted = $Objective->delete($_POST['id']);
    echo json_encode($deleted);
    return;
}

if (isset($_GET['logout'])) {
    $Objective->dologout();
}
?>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
    <title>E-Major : Objectives</title>

    <link rel="stylesheet" href="lib/jquery-ui/css/smoothness/jquery-ui-1.8.15.custom.css" type="text/css"/>
    <link rel="stylesheet" href="lib/harvesthq-chosen/chosen.css" type="text/css"/>
    <link rel="stylesheet" href="lib/elfinder/css/elfinder.full.css" type="text/css"/>
    <link rel="stylesheet" href="lib/visualize/visualize.css" media="all" type="text/css"/>
    <link rel="stylesheet" href="lib/datatables/css/table_jui.css" type="text/css"/>
    <link rel="stylesheet" href="lib/gritter/css/jquery.gritter.css" type="text/css"/>
    <link rel="stylesheet" href="lib/fancybox/jquery.fancybox-1.3.4.css" type="text/css"/>
    <link rel="stylesheet" href="lib/file-uploader/fileuploader.css" type="text/css"/>
    <link rel="stylesheet" href="lib/timepicker-addon/jquery-ui-timepicker-addon.css" type="text/css"/>
    <link rel="stylesheet" href="lib/fullcalendar/fullcalendar.css" type="text/css"/>
    <link rel="stylesheet" href="css/style.css" media="all" type="text/css"/>

    <script type="text/javascript" src="js/head.min.js"></script>
    <style>
        .hide {
            display: none;
        }
    </style>

</head>


<body class="bg_c sidebar fixed ">
<div id="top_bar">
    <div class="wrapper cf">
        <ul class="fl">
            <li class="sep">Welcome <a
                href="#"><?php echo $Objective->get('uname') !== false ? ucfirst($Objective->get('uname')) : ''; ?></a>
            </li>
            <li class="sep"><a href="?logout=1">Logout</a></li>
        </ul>
        <ul class="fr">
            <li><strong>E-Major Objectives</strong></li>
        </ul>
    </div>
</div>

<div id="header">
    <div class="wrapper cf">
        <div class="cf" style="margin: 0 auto; width: 80%; text-align: center">
            <div class="logo fl"></div>
            <ul class="fr cf" id="main_nav">
                <li class="nav_item lgutipT" title="Questions">
                    <a href="dashboard.php" class="main_link"><img class="img_holder"
                                                                   src="images/blank.gif"
                                                                   style="background: url(images/icons/computer_imac.png) no-repeat center center"
                                                                   alt="Questions"/><span>Questions</span></a><img
                    class="tick tick_a" alt="Objectives" src="images/blank.gif"/></li>
                <li class="nav_item lgutipT active" title="Objectives"><a
                    href="javascript:void(0)" class="main_link"><img src="images/blank.gif"
                                                                     class="img_holder"
                                                                     style="background: url(images/icons/file_cabinet.png) no-repeat center center"
                                                                     alt="Objectives"/><span>Objectives</span></a><img
                    class="tick tick_a" alt="Scores" src="images/blank.gif"/></li>
                <li class="nav_item lgutipT" title="Scores"><a
                    href="score.php" class="main_link"><img src="images/blank.gif"
                                                            class="img_holder"
                                                            style="background: url(images/icons/image2_2.png) no-repeat center center"
                                                            alt="Scores"/><span>Scores</span></a><img
                    class="tick tick_a" alt="Scores" src="images/blank.gif"/></li>


                <li class="nav_item lgutipT" title="Schools">
                    <a href="schools.php" class="main_link"><img class="img_holder"
                                                                 src="images/blank.gif"
                                                                 style="background: url(images/icons/book.png) no-repeat center center"
                                                                 alt="Questions"/><span>Schools</span></a><img
                    class="tick tick_a" alt="Schools" src="images/blank.gif"/></li>

                <li class="nav_item lgutipT" title="Majors">
                    <a href="majors.php" class="main_link"><img class="img_holder"
                                                                src="images/blank.gif"
                                                                style="background: url(images/icons/pencil.png) no-repeat center center"
                                                                alt="Questions"/><span>Majors</span></a><img
                    class="tick tick_a" alt="Schools" src="images/blank.gif"/></li>
                <li class="nav_item lgutipT" title="Students"><a
                    href="student.php" class="main_link"><img src="images/blank.gif"
                                                              class="img_holder"
                                                              style="background: url(images/icons/users2.png) no-repeat center center"
                                                              alt=""/><span>Students</span></a><img
                    class="tick tick_a" alt="Students" src="images/blank.gif"/></li>

                <li class="nav_item lgutipT" title="Counsellors"><a href="user.php" class="main_link"><img
                    src="images/blank.gif" class="img_holder"
                    style="background: url(images/icons/create_write.png) no-repeat center center" alt=""/><span>Counsellors</span></a><img
                    class="tick tick_a" alt="Counsellors" src="images/blank.gif"/></li>

                <li class="nav_item lgutipT" title="Reports"><a href="report.php" class="main_link"><img
                    src="images/blank.gif" class="img_holder"
                    style="background: url(images/icons/chart8.png) no-repeat center center"
                    alt=""/><span>Reports</span></a><img class="tick tick_a" alt="" src="images/blank.gif"/></li>
            </ul>
        </div>
    </div>
</div>
<div id="main">
    <div class="wrapper cf">
        <div id="main_section" class="cf brdrrad_a">
            <div id="content_wrapper">
                <?php if (!is_null($saved)) { ?>
                <div class="msg_box <?php echo $saved['type'] ?>"><?php echo $saved['msg'] ?>.<img
                    src="images/blank.gif" class="msg_close" alt=""/></div>
                <?php } ?>
                <form action="" id="form_a" method="post" novalidate="novalidate">

                    <div class="cf sepH_c">
                        <div id="content_actions" class="fr" style="">
                            <input type="reset" name="reset" value="Reset" class="btn btn_a">
                            <input type="submit" name="save" value="Save" class="btn btn_d">

                        </div>
                        <h1 class="fl">Select a question to add objective</h1>
                    </div>
                    <div class="msg_box msg_error" id="form_a_errors" style="display:none"></div>

                    <div class="content_panes">
                        <div>

                            <div class="formEl_a">

                                <p class="fl">Select a question</p>
                                <?php if ($questions) { ?>
                                <table cellpadding="0" cellspacing="0" border="0" class="display formEl_a data_table">
                                    <thead>
                                    <tr>
                                        <th class="chb_col">
                                            <div class="th_wrapp"><input type="checkbox" class="chSel_all inpt_c1"/>
                                            </div>
                                        </th>
                                        <th>
                                            <div class="th_wrapp">No.</div>
                                        </th>
                                        <th>
                                            <div class="th_wrapp">Level</div>
                                        </th>
                                        <th>
                                            <div class="th_wrapp">Question</div>
                                        </th>
                                        <th style="width: 100px;">
                                            <div class="th_wrapp">Date</div>
                                        </th>
                                        <th class="hide">&nbsp;</th>
                                    </tr>
                                    </thead>
                                    <tbody>

                                        <?php while ($question = mysql_fetch_object($questions)) { ?>
                                    <tr data-id="<?php echo $question->id; ?>">
                                        <td class="chb_col"><input type="checkbox" name="row_sel" class="inpt_c1"/></td>
                                        <td><?php echo $question->number; ?></td>
                                        <td><?php echo $question->level; ?></td>
                                        <td>
                                            <a href="javascript:void(0);" class="lgutipT"
                                               title="<?php echo $question->question ?>"><?php echo strlen($question->question) > 110 ? substr($question->question, 0, 110) . '...' : $question->question; ?></a>
                                        </td>
                                        <td><?php echo $question->date; ?></td>
                                    </tr>

                                        <?php } ?>
                                    </tbody>
                                </table>
                                <?php }?>
                                <div class="objectiveComponent hide">
                                    <div class="sepH_b">
                                        <div class="dp50">
                                            <label for="objective_index" class="lbl_a">Objective Index</label>
                                            <select name="objective_index" id="objective_index" style="width: 80px;">
                                                <option value="a">a</option>
                                                <option value="b">b</option>
                                                <option value="c">c</option>
                                                <option value="d">d</option>
                                                <option value="e">e</option>
                                                <option value="f">f</option>
                                            </select>
                                            <br />

                                            <?php if ($groups) { ?>
                                            <label for="recomendation_group_id" class="lbl_a">Recommendation Group</label>
                                            <select id="recomendation_group_id" name="recomendation_group_id" style="width: 140px;">
                                                <?php while ($group = mysql_fetch_object($groups)) { ?>
                                                <option value="<?php echo $group->id; ?>"><?php echo $group->group; ?></option>
                                                <?php } ?>
                                            </select>
                                            <?php } ?>
                                            <br />
                                            <label for="datepick" class="lbl_a">Date</label>
                                            <input type="text" class="inpt_b datepicker" readonly="readonly"
                                                   name="date"/><br/>
                                            <label for="objective" class="lbl_a">Objective</label>
                                            <textarea name="objective"></textarea>
                                            <input type="hidden" name="question_id" value="">
                                        </div>
                                        <div class="dp50">
                                        </div>

                                    </div>
                                </div>

                            </div>
                        </div>
                    </div>
                </form>


                <!-- TABLE  -->
                <div class="clear"></div>
                <br/>
                <br/>

                <div class="sepH_c">
                    <h2 class="sepH_b">Objectives</h2>

                    <?php $result = $Objective->find(); ?>
                    <?php if ($result) { ?>
                    <table cellpadding="0" cellspacing="0" border="0" class="display formEl_a objective_data_table">
                        <thead>
                        <tr>
                            <th class="chb_col">
                                <div class="th_wrapp"><input type="checkbox" class="chSel_all inpt_c1"/></div>
                            </th>
                            <th>
                                <div class="th_wrapp">Objective</div>
                            </th>
                            <th style="width: 80px;">
                                <div class="th_wrapp">Group</div>
                            </th>
                            <th>
                                <div class="th_wrapp">Question</div>
                            </th>
                            <th style="width: 40px;">
                                <div class="th_wrapp">Que: No.</div>
                            </th>
                            <th style="width: 40px;">
                                <div class="th_wrapp">&nbsp;</div>
                            </th>
                        </tr>
                        </thead>
                        <tbody>

                            <?php while ($objective = mysql_fetch_object($result)) { ?>
                        <tr data-table="objectives" data-id="<?php echo $objective->id; ?>">
                            <td class="chb_col"><input type="checkbox" name="row_sel" class="inpt_c1"/></td>
                            <td style="width: 25%;">
                                <a href="#edit_form" class="lgutipT edit fncyBx" data-target="edit_form"
                                   title="<?php echo $objective->objective ?>"><?php echo strlen($objective->objective) > 50 ? substr($objective->objective, 0, 50) . '...' : $objective->objective; ?></a>
                            </td>
                            <td>
                                <?php $objectiveGroup = $Objective->findById('recomendation_groups', false, $objective->recomendation_group_id) ?>
                                <?php if ($objectiveGroup) { echo $objective->objective_index . ': '. $objectiveGroup->group; } ?>
                            </td>
                            <?php $objectiveQuestion = $Objective->getObjectiveQuestion($objective->question_id); ?>
                            <td style="width: 38%;"><a href="javascript:void(0);" class="lgutipT"
                                   title="<?php echo $objectiveQuestion->question; ?>"><?php echo strlen($objectiveQuestion->question) > 50 ? substr($objectiveQuestion->question, 0, 50) . '...' : $objectiveQuestion->question; ?></a>
                            </td>
                            <td><?php echo $objectiveQuestion->number; ?></td>
                            <td>
                                <a href="javascript:void(0);" class="delete delete_all_dt"
                                   data-target="delete_form"><img src="images/delete_icon.png" width="12"></a>&nbsp;&nbsp;
                                <a href="#edit_form" class="edit fncyBx" data-target="edit_form"><img
                                    src="images/edit.png" width="12"></a>
                            </td>
                        </tr>

                            <?php } ?>
                        </tbody>
                    </table>
                    <?php }?>

                </div>
                <!-- END TABLE-->


            </div>

        </div>
    </div>
</div>

<div id="footer">
    <div class="wrapper">
        <div class="cf ftr_content">
            <a href="javascript:void(0)" class="toTop">Back to top</a>
        </div>
    </div>
</div>
<script type="text/javascript">
    head.js(
        "js/jquery-1.7.2.min.js",
        "lib/jquery-ui/jquery-ui-1.8.15.custom.min.js",
        "lib/datatables/jquery.dataTables.min.js",
        "lib/datatables/dataTables.plugins.js",
        "lib/harvesthq-chosen/chosen.jquery.min.js",
        "lib/elfinder/js/elfinder.full.js",
        "lib/visualize/visualize.jQuery.js",
        "lib/visualize/excanvas.js",
        "lib/fusion-charts/FusionCharts.js",
        "lib/gritter/jquery.gritter.min.js",
        "lib/fancybox/jquery.easing-1.3.pack.js",
        "lib/fancybox/jquery.fancybox-1.3.4.pack.js",
        "lib/file-uploader/fileuploader.js",
        "lib/tiny-mce/jquery.tinymce.js",
        "js/jquery.microaccordion.js",
        "js/jquery.stickyPanel.js",
        "js/jquery.text-overflow.min.js",
        "js/xbreadcrumbs.js",
        "lib/slidernav/slidernav.js",
        "lib/styled-checkboxes/iphone-style-checkboxes.js",
        "lib/jquery-raty/jquery.raty.min.js",
        "lib/timepicker-addon/jquery-ui-timepicker-addon.js",
        "js/jquery.faq.js",
        "js/jquery.tools.min.js",
        "lib/jquery-validation/jquery.validate.js",
        "lib/fullcalendar/fullcalendar.min.js",
        "js/lagu.min.js",
        "js/Custom.js",
        function () {
            lga_helper.init();
            lga_bredcrumbs.init();
            lga_scrolltoTop.init();
            lga_messages.init();
            lga_toggleBox.init();
            lga_RemoveBox.init();
            lga_sidebar.lga_accordion();
            lga_sticky.sticky_bredcrumbs();
            lga_slidingPanel.init();
            lga_tips.init();
            lga_externalLink.init();
            lga_datepicker.init();
            lga_datepicker_inline.init();
            //Custom.init();
        }
    );

</script>
<script type="text/javascript"><!--
	head.ready(function() {

        $('.chSel_all').click(function () {
			$(this).closest('table').find('input[name=row_sel]').attr('checked', this.checked);
		});
		$(".delete_all_simple").click(function () {
			$('input[name=row_sel]:checked', '.smpl_tbl').closest('tr').fadeTo(600, 0, function () {
				$(this).remove();
				$('.chSel_all','.smpl_tbl').attr('checked',false);
			});
			return false;
		});

        $('.data_table').dataTable({
			"aaSorting": [[ 1, "asc" ]],
			"aoColumns": [
				{ "bSortable": false },
				null,
				null,
				{ "sType": "formatted-num" },
				{ "sType": "formatted-num" }
			]
		});
		$('.objective_data_table').dataTable({
			"aaSorting": [[ 1, "asc" ]],
			"aoColumns": [
				{ "bSortable": false },
				null,
				null,
				{ "sType": "formatted-num" },
				{ "sType": "formatted-num" },
				{ "sType": "formatted-num" },
			]
		});
	});
--></script>

<!-- MODAL BOX -->
<div style="display:none; width: 60%;">
    <form id="edit_form" method="post" action="" class="formEl_a">
        <div class="objectiveComponent">
            <div class="msg_box"><img src="images/blank.gif" class="msg_close" alt=""/></div>
            <fieldset>
                <legend>Edit Objective</legend>
                <div class="sepH_b">
                    <div>
                        <?php if ($questions = $Objective->getQuestions()) { ?>
                        <label for="question_id" class="lbl_a">Question</label>
                        <select name="question_id" id="question_id">
                            <?php while ($question = mysql_fetch_object($questions)) { ?>
                            <option value="<?php echo $question->id; ?>"><?php echo $question->question; ?></option>
                            <?php } ?>
                        </select>
                        <?php } ?>
                    </div>

                    <div class="dp50">
                        <label class="lbl_a">Objective Index</label>
                        <select name="objective_index" style="width: 80px;">
                            <option value="a">a</option>
                            <option value="b">b</option>
                            <option value="c">c</option>
                            <option value="d">d</option>
                            <option value="e">e</option>
                            <option value="f">f</option>
                        </select>
                        &nbsp;&nbsp;
                        <?php $groups = $Objective->getRecommendationGroups(); ?>
                        <?php if ($groups) { ?>
                        <label for="recomendation_group_id" class="lbl_a">Recommendation Group</label>
                        <select id="recomendation_group_id" name="recomendation_group_id" style="width: 100px;">
                            <?php while ($group = mysql_fetch_object($groups)) { ?>
                            <option value="<?php echo $group->id; ?>"><?php echo $group->group; ?></option>
                            <?php } ?>
                        </select>
                        <?php } ?>
                        <label for="datepick" class="lbl_a">Date</label>
                        <input type="text" id="datepick" class="inpt_b datepicker" readonly="readonly"
                               name="date"/><br/>
                        <label for="objective" class="lbl_a">Objective</label>
                        <textarea name="objective" id="objective"></textarea>
                        <input type="hidden" name="question_id" value="">
                    </div>
                </div>
                <input type="hidden" name="id">
            </fieldset>
        </div>
        <div class="cf sepH_c">
            <div class="fr" style="">
                <input type="reset" name="reset" value="Reset" class="btn btn_a">
                <input type="submit" name="update" value="Update" class="btn btn_d">
            </div>
        </div>
    </form>
</div>
<!-- END MODAL BOX -->

</body>
</html>